Python bindings

Python bindings provide access to the full range of the Java TPT API. They can be used in API scripts or directly in TPT projects.

Python bindings used in API scripts can be executed either from the command line, enter tpt.exe --run apiserver <apiRunScript>, see Command line options, or from the API Script Editor view, see TPT API scripts.

They can also be executed from the Batch Runner view, see Automatic test execution - Executing tests with batch files.

There are two API scripts available to try out in the <TPT installation folder>\examples\TPT API folder. For passing arguments to API scripts, see the following example:

Example

Suppose there is the following API script:

import sys

print "The name of the script is:", sys.argv[0]

print "The number of arguments is:", len(sys.argv)

print "The arguments are:" , str(sys.argv)

sys.argv() is an array for command line arguments in Python. For example, it can be used to output script name, arguments and argument list in the command line.

Command line output

The first element of sys.argv[0] is the name of the script being executed.

Python bindings used in TPT projects can be set up in Execution|Platform Configuration|Custom Script or Execution|Execution Configuration|Custom Script.

If set up in the Platform Configuration dialog, they run before the platform starts or after the platform shuts down. If set up in the Execution Configuration dialog, they run at the beginning or end of the test execution, see Custom Scripts.

Python scripts set up in the 'Execution Configuration dialog'

When using the Python bindings, the following classes and constants can be used without importing Java packages, see Automatically imported classes.